import http from '@/api'
import { PORT1 } from '@/api/config/port'

import { Violation } from '../interface'
import { Entity, LoginRep, OtpCreateRep, ReplyReq, ReplyRes } from '../interface/entity'

// 发送短信
export const OtpCreate = (params: OtpCreateRep) => {
  return http.post<any>(PORT1 + `/entity/otp/create`, params)
}

// 登录
export const Login = (params: LoginRep) => {
  return http.post<any>(PORT1 + `/entity/account/login`, params, { loading: true })
}

export const Profile = (params = {}) => {
  return http.post<any>(PORT1 + `/entity/account/profile`, params)
}

// 退出登录
export const LoginOut = () => {
  return http.get<any>(PORT1 + `/entity/account/logout`)
}

// 创建 Violation
export const CreateViolation = (params: Partial<Violation>) => {
  return http.post(PORT1 + `/entity/violation/create`, params, { loading: true })
}

// 获取消息列表
export const ReplyList = (params: { refNumber: string }) => {
  return http.post<ReplyRes[]>(PORT1 + `/entity/violation/reply/list`, {}, { params })
}

// 消息回复
export const Reply = (params: ReplyReq) => {
  return http.post(PORT1 + `/entity/violation/reply`, params, { loading: true })
}

// 获取 entity 信息
export const EntityInfo = (params: { id: string }) => {
  return http.get<Entity>(PORT1 + `/entity/entity/get`, params)
}

// 修改 entity 信息
export const UpdateEntityInfo = (params: Entity) => {
  return http.post(PORT1 + `/entity/entity/update`, params)
}

// entity上传文件
export const UploadFile = (params: any) => {
  return http.post<string>(PORT1 + `/entity/file/upload `, params, { loading: true, cancel: false })
}

// entity下载文件
export const FileLink = (params: any) => {
  return http.get<string>(PORT1 + `/entity/file/link`, params, { loading: true, cancel: false })
}
